package com.lottery.ruok.lottrey.adapter;

import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.OfficalLotteryDetailActivity;
import com.lottery.ruok.lottrey.retrofitModule.response.GetLotteryDetailResponse;

/**
 * Created by ASUS on 2017/11/13.
 */

public class LotteryChangeTypeAdapter1 extends BaseAdapter {
    private FragmentActivity fragmentActivity;
    private GetLotteryDetailResponse getLotteryDetailResponse;
    public LotteryChangeTypeAdapter1(FragmentActivity fragmentActivity, GetLotteryDetailResponse getLotteryDetailResponse){
        this.fragmentActivity = fragmentActivity;
        this.getLotteryDetailResponse = getLotteryDetailResponse;
    }

    @Override
    public int getCount() {
        if(getLotteryDetailResponse == null || getLotteryDetailResponse.getLayouts() == null){
            return 0;
        }
        return getLotteryDetailResponse.getLayouts().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(fragmentActivity).inflate(R.layout.layout_type_item, null);
            holder = new ViewHolder();
            holder.name = view.findViewById(R.id.name);
            view.setTag(holder);
        }

        if(getLotteryDetailResponse.getLayouts() != null) {
            holder.name.setText(getLotteryDetailResponse.getLayouts().get(i).getName());
        }
        if (i == ((OfficalLotteryDetailActivity) fragmentActivity).typePosition1) {
            holder.name.setTextColor(Color.parseColor("#661dac"));
            holder.name.setBackgroundResource(R.drawable.bg_corners_3);
        } else {
            holder.name.setTextColor(Color.parseColor("#3f3f3f"));
            holder.name.setBackgroundResource(0);
        }

        return view;
    }

    static class ViewHolder {
        TextView name;
    }
}
